import { ResultCodeEnum } from "./httpEnum";
import { useI18n } from "/@/locales/useI18n";

export default function (code: number | null): string | null {
  const { t } = useI18n();
  switch (code) {
    case ResultCodeEnum.ACCOUNT_PWD_ERR:
      return t("aiot.login.accountPwdErr");
    case ResultCodeEnum.SYSTEM_BUSY:
      return t("common.systemBusy");
    case ResultCodeEnum.JWT_PASSWORD_INVALID:
      return t("aiot.login.passErr");
    case ResultCodeEnum.JWT_PARSER_TOKEN_FAIL:
      return t("common.parseTokenFail");
    case ResultCodeEnum.JWT_NOT_LOGIN:
    case ResultCodeEnum.JWT_TOKEN_EXPIRED:
      return t("common.loginTimeout");
    case ResultCodeEnum.UNAUTHORIZED:
      return t("common.noAuthShort");
  }
  const key = `baseData.exception.${code}`;
  const result = t(key);
  return result === key ? null : result;
}
